import 'dotenv/config';
import type { VercelRequest, VercelResponse } from '@vercel/node';
import axios from 'axios';

const { API_URL, ACCESS_KEY } = process.env;

export default async (request: VercelRequest, response: VercelResponse) => {
   const code = request.query.code;
   if (!code)
      return response.status(400)
         .json({ messsage: "the value of【code】is empty" }).end();

   let url = `${API_URL}?data_type=all&ak=${ACCESS_KEY}&district_id=${code}`
   const { data: { status, ...result } } = await axios.get(url)

   console.log(`${JSON.stringify(result.result, null, 4)}`)

   return response.json({
      data: result.result
   })
}
